package lee.vioson.remotedata.manager

import android.content.Context
import android.os.Parcel
import android.os.Parcelable
import android.os.Parcelable.Creator
import com.google.gson.Gson
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import kotlinx.parcelize.Parceler
import lee.vioson.remotedata.bean.HomeData

/**
 *Author:viosonlee
 *Date:2023/6/15
 *DESCRIPTION:
 */
object HomeDataManager {
    suspend fun cacheHomeData(context: Context, homeData: HomeData) {
        withContext(Dispatchers.IO) {
            context.cacheUtils.put(KEY_HOME_DATA, Gson().toJson(homeData))
        }
    }

    suspend fun getCachedHomeData(context: Context): HomeData? {
        return withContext(Dispatchers.IO) {
            val json = context.cacheUtils.getString(KEY_HOME_DATA, "{}")
            Gson().fromJson(json, HomeData::class.java)
        }
    }
}